#!/usr/bin/env python
# coding=utf-8
import sys, httplib,string
import os,re
import glob
from pyExcelerator import *
    
re_date=re.compile(r"^[0-9]*-[0-9]*-[0-9]*", re.X|re.S)
if __name__ == '__main__':
    
    count=0
    price1=0
    price2=0
    list = glob.glob('/data/projects/vacationspider/spider_vacations/uploads/*.xls')
    for l in list:
        sheet = parse_xls(l.decode('gbk'))[0][1]
        maxRow=0
        for row in sheet.keys():
            if row[0]>maxRow:
                maxRow=row[0]
        #print u'最大行数:',maxRow
        for i in range(1,maxRow,1):
            if sheet.has_key((i,0)) and sheet.has_key((i-1,0)):
                if u'发团时间'==sheet[(i-1,0)] and re_date.search(sheet[(i,0)]):
                    if int(sheet[(i,2)])>0 and int(sheet[(i+1,2)])>0:
                        count=count+1
                        price1=price1+int(sheet[(i,2)])
                        price2=price2+int(sheet[(i+1,2)])
                        print count,'\t',l.decode('gbk')[12:30].replace('.xls',''),'\t',sheet[(i,2)],'\t',sheet[(i+1,2)]
                    break
    print count,'\t','平均值:','\t',price1/count,'\t',price2/count